home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / SOUND.SWG / 0014_MIDI.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-04  |  11KB  |  220 lines

  1. --------M-MIDI-M----------------------------
  2.  
  3. The  MIDI  file  format  is used to  store  MIDI  song data on disk. The
  4. discussed   version  of  the  MIDI  file   spec  is  the  approved  MIDI
  5. Manufacturers'  Associations format version 0.06  of (3/88). The contact
  6. address  is  listed  in the adresses  file.  Version  1.0 is technically
  7. identical  but  the description has  been rewritten. The description was
  8. made  by  Dave  Oppenheim, most of the  text  was taken right out of his
  9. document.
  10.  
  11. MIDI  files contain one or more  MIDI streams, with time information for
  12. each  event.  Song,  sequence,  and  track  structures,  tempo  and time
  13. signature   information,  are  all  supported.  Track  names  and  other
  14. descriptive  information  may be stored with  the MIDI data. This format
  15. supports multiple tracks and multiple sequences so that if the user of a
  16. program which supports multiple tracks intends to move a file to another
  17. one, this format can allow that to happen.
  18.  
  19. The  MIDI  files are block oriented  files, currently only 2 block types
  20. are defined, header and track data. Opposed to the IFF and RIFF formats,
  21. no global header is given, so that the validation must be done by adding
  22. the different block sizes.
  23.  
  24. A MIDI file always starts with a header block, and is followed by one or
  25. more track block.
  26.  
  27. The format of the header block :
  28.  
  29. OFFSET              Count TYPE   Description
  30. 0000h                   4 char   ID='MThd'
  31. 0004h                   1 dword  Length of header data (=6)
  32. 0008h                   1 word   Format specification
  33.                                    0 - one, single multi-channel track
  34.                                    1 - one or more simultaneous tracks
  35.                                    2 - one or more sequentially independent
  36.                                        single-track patterns
  37. 000Ah                   1 word   Number of track blocks in the file
  38. 000Ch                   1 int    Unit of delta-time values.
  39.                                  If negative :
  40.                                    Absolute of high byte :
  41.                                      Number of frames per second.
  42.                                    Low byte :
  43.                                      Resolution within one frame
  44.                                  If positive, division of a quarter-note.
  45.  
  46. The track data format :
  47. The  MTrk block type is where actual song data is stored. It is simply a
  48. stream  of  MIDI  events (and  non-MIDI  events), preceded by delta-time
  49. values.
  50.  
  51. Some numbers in MTrk blocks are represented in a form called a variable-
  52. length  quantity.  These numbers are represented  7  bits per byte, most
  53. significant  bits  first. All bytes except the  last have bit 7 set, and
  54. the last byte has bit 7 clear. If the number is between 0 and 127, it is
  55. thus  represented exactly as one byte.  Since this explanation might not
  56. be too clear, some examples :
  57.  
  58.         Number (hex)    Representation (hex)
  59.         00000000        00
  60.         00000040        40
  61.         0000007F        7F
  62.         00000080        81 00
  63.         00002000        C0 00
  64.         00003FFF        FF 7F
  65.         001FFFFF        FF FF 7F
  66.         08000000        C0 80 80 00
  67.         0FFFFFFF        FF FF FF 7F
  68.  
  69. The  largest  number which is allowed  is 0FFFFFFF so that the variable-
  70. length  representation  must  fit  in  32  bits  in  a  routine to write
  71. variable-length numbers.
  72.  
  73. Each  track block contains one or  more MIDI events, each event consists
  74. of a delta-time and the number of the event. The delta-time is stored as
  75. a  variable-length quantity and represents the  time to delay before the
  76. following  event.  A  delta-time  of  0  means,  that  the  event occurs
  77. simultaneous  with the previous event or occurs  right at the start of a
  78. track. The delta-time unit is specified in the header block.
  79.  
  80. Format of track information block :
  81. OFFSET              Count TYPE   Description
  82. 0000h                   4 char   ID='MTrk'
  83. 0004h                   1 dword  Length of header data
  84. 0008h                   ? rec    <delta-time>, <event>
  85.  
  86. Three  types  of events are defined,  MIDI event, system exclusive event
  87. and  meta  event.  The  first  event  in  a  file  must  specify status;
  88. delta-time   itself   is  not  an   event.   Meta  events  are  non-MIDI
  89. informations.
  90.  
  91. The format of the meta event :
  92. OFFSET              Count TYPE   Description
  93. 0000h                   1 byte   ID=FFh
  94. 0001h                   1 byte   Type (<=128)
  95. 0002h                   ? ?      Length of the data, 0 if no data
  96.                                  stored as variable length quantity
  97.                         ? byte   Data
  98.  
  99. A  few meta-events are defined. It is  not required for every program to
  100. support every meta-event. Meta-events initially defined include:
  101.  
  102. FF 00 02 ssss   Sequence Number
  103. This  optional  event,  which must occur  at  the  beginning of a track,
  104. before  any  nonzero  delta-times,  and  before  any  transmittable MIDI
  105. events, specifies the number of a sequence.
  106.  
  107. FF 01 len text  Text Event
  108. Any  amount of text describing anything. It is a good idea to put a text
  109. event  right at the beginning of a track,  with the name of the track, a
  110. description  of  its intended orchestration,  and  any other information
  111. which the user wants to put there. Programs on a computer which does not
  112. support  non-ASCII  characters should ignore  those  characters with the
  113. hi-bit  set.  Meta  event types 01  through  0F are reserved for various
  114. types  of  text  events, each of  which  meets the specification of text
  115. events(above) but is used for a different purpose:
  116.  
  117. FF 02 len text  Copyright Notice
  118. Contains  a copyright notice as printable  ASCII text. The notice should
  119. contain  the characters (C), the year of the copyright, and the owner of
  120. the copyright. If several pieces of music are in the same MIDI file, all
  121. of the copyright notices should be placed together in this event so that
  122. it  will be at the beginning of the file. This event should be the first
  123. event in the first track block, at time 0.
  124.  
  125. FF 03 len text  Sequence/Track Name
  126. If  in a format 0 track, or the first track in a format 1 file, the name
  127. of the sequence. Otherwise, the name of the track.
  128.  
  129. FF 04 len text  Instrument Name
  130. A description of the type of instrumentation to be used in that track.
  131.  
  132. FF 05 len text  Lyric
  133. A  lyric  to be sung. Generally, each  syllable will be a separate lyric
  134. event which begins at the event's time.
  135.  
  136. FF 06 len text  Marker
  137. Normally in a format 0 track, or the first track in a format 1 file. The
  138. name  of  that  point  in the sequence,  such  as  a rehearsal letter or
  139. section name ("First Verse", etc.).
  140.  
  141. FF 07 len text  Cue Point
  142. A  description of something happening on a film or video screen or stage
  143. at  that point in the musical  score ("Car crashes into house", "curtain
  144. opens", "she slaps his face", etc.)
  145.  
  146. FF 2F 00 End of Track
  147. This event is not optional. It is included so that an exact ending point
  148. may be specified for the track, so that it has an exact length, which is
  149. necessary for tracks which are looped or concatenated.
  150.  
  151. FF 51 03 tttttt Set Tempo, in microseconds per MIDI quarter-note
  152. This   event   indicates  a  tempo   change.   Another  way  of  putting
  153. "microseconds  per  quarter-note"  is "24ths  of  a microsecond per MIDI
  154. clock".  Representing  tempos as time per  beat instead of beat per time
  155. allows  absolutely  exact dword-term  synchronization  with a time-based
  156. sync  protocol such as SMPTE time code or MIDI time code. This amount of
  157. accuracy provided by this tempo resolution allows a four-minute piece at
  158. 120  beats  per minute to be accurate within  500 usec at the end of the
  159. piece.  Ideally, these events should only  occur where MIDI clocks would
  160. be  located  Q  this convention is  intended  to  guarantee, or at least
  161. increase  the  likelihood, of  compatibility  with other synchronization
  162. devices  so  that a time signature/tempo  map  stored in this format may
  163. easily be transferred to another device.
  164.  
  165. FF 54 05 hr mn se fr ff SMPTE Offset
  166. This  event,  if present, designates the  SMPTE  time at which the track
  167. block is supposed to start. It should be present at the beginning of the
  168. track,   that  is,  before  any  nonzero  delta-times,  and  before  any
  169. transmittable  MIDI  events.  The hour must  be  encoded  with the SMPTE
  170. format,  just as it is in MIDI Time  Code. In a format 1 file, the SMPTE
  171. Offset  must be stored with the tempo map,  and has no meaning in any of
  172. the  other tracks. The ff field contains fractional frames, in 100ths of
  173. a  frame,  even  in SMPTE-based tracks  which  specify a different frame
  174. subdivision for delta-times.
  175.  
  176. FF 58 04 nn dd cc bb    Time Signature
  177. The time signature is expressed as four numbers. nn and dd represent the
  178. numerator  and denominator of the time signature as it would be notated.
  179. The denominator is a negative power of two: 2 represents a quarter-note,
  180. 3  represents an eighth-note, etc. The cc parameter expresses the number
  181. of  MIDI  clocks  in a metronome  click.  The bb parameter expresses the
  182. number of notated 32nd-notes in a MIDI quarter- note (24 MIDI Clocks).
  183.  
  184. FF 59 02 sf mi  Key Signature
  185.         sf = -7:  7 flats
  186.         sf = -1:  1 flat
  187.         sf = 0:  key of C
  188.         sf = 1:  1 sharp
  189.         sf = 7: 7 sharps
  190.  
  191.         mi = 0:  major key
  192.         mi = 1:  minor key
  193.  
  194. FF 7F len data  Sequencer-Specific Meta-Event
  195.         Special  requirements  for  particular  sequencers  may use this
  196. event  type:  the  first  byte or bytes  of  data  is a manufacturer ID.
  197. However,  as this is an interchange format, growth of the spec proper is
  198. preferred to use of this event type. This type of event may be used by a
  199. sequencer  which elects to use this  as its only file format; sequencers
  200. with their established feature-specific formats should probably stick to
  201. the standard features when using this format.
  202.  
  203. The  system  exclusive event is used  as  an escape to specify arbitrary
  204. bytes  to  be transmitted. The system  exclusive event has two forms, to
  205. compensate  for some manufacturer-specific modes,  the F7h event is used
  206. if a F0h is to be transmitted. Each system exclusive event must end with
  207. an F7h event.
  208.  
  209. The format of a system exclusive event :
  210. OFFSET              Count TYPE   Description
  211. 0000h                   1 byte   ID=F0h,ID=F7h
  212. 0001h                   ? ?      Length as variable length qty.
  213.                         ? byte   bytes to be transmitted
  214.  
  215. EXTENSION:MID,MIDI
  216. OCCURENCES:PC,MAC
  217. PROGRAMS:Cubase
  218. VALIDATION:
  219.  
  220.